﻿@using Property;
@{
    ViewBag.Title = "DictionaryIndex";
}
@model string
@section head
{
    <link href="@Url.Content("~/ScriptPlugin/easyui/themes/gray/easyui.css")" rel="stylesheet" />
    <link href="@Url.Content("~/ScriptPlugin/easyui/themes/icon.css")" rel="stylesheet" />
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/jquery.easyui.min.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/locale/easyui-lang-zh_CN.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/plugins/datagrid-groupview.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/plugins/datagrid-detailview.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Scripts/KingsSharp.DataGrid.Filter.js")"></script>
    <link href="@Url.Content("~/App_Themes/default/icons/iconcontent/iconfont.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/App_Themes/default/icons/iconcontent/demo.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/ScriptPlugin/ztree/js/jquery.ztree.core-3.5.js")" type="text/javascript"></script>
    <link href="@Url.Content("~/ScriptPlugin/ztree/css/zTreeStyle/zTreeStyle.css")" rel="stylesheet" type="text/css" />
}
<div style="float:left;width:190px;height:100%">
    <div class="content-bar-color" style="height:34px; line-height: 34px; text-align: center">
        字典类别
    </div>
    <div class="content-pannel-buttons" style="border-bottom:1px solid #cccccc">
        <a onclick="dictionaryTypeAdd()"><b class="p-icon-add">新增</b></a>
        <a onclick="dictionaryTypeEdit()"><b class="p-icon-edit">编辑</b></a>
    </div>
    <div style="padding-top:1px">
        <ul id="tree" class="ztree"></ul>
    </div>
</div>
<div style="position:absolute;left:190px;right:0;height:100%">
    <div id="grid-bundles">
        <div id="toolpannel">
            <div class="content-pannel-buttons">
                <a><b class="p-icon-reload">刷新 </b></a><a onclick="dictionaryAdd()">
                    <b class="p-icon-add">
                        新增
                    </b>
                </a><a onclick="rowEdit()"><b class="p-icon-edit">编辑</b></a>
                <a onclick="rowDelete()"><b class="p-icon-delete">删除</b></a>
                <a onclick="$('#grid-bundles').datagrid('load')">
                    <b class="p-icon-serch">查询</b>
                </a><a onclick="showicon()"> <b class="p-icon-clear">清空</b></a>
            </div>
            <div class="datagrid-filter-pannel" id="filterpannel">
                <table class="content-table-serch">
                    <tr>
                        <th>
                            字典名称
                            <input type="hidden" data-filter="true" id="Type" name="Type" />
                            <input type="hidden" data-filter="true" id="Parent.Id" name="Parent.Id" />
                        </th>
                        <td>
                            <input type="text" name="Name" data-filter="true" />
                            <a class="p-icon-filter p-icon-filter-style" style="display: block; width: 22px;
                                        height: 22px; float: left">@Html.GetFilterItem("Name", typeof(string))</a>
                                    </td>
                                    <th>
                                        排序号
                                    </th>
                                    <td>
                                        <input type="text" name="Order" data-filter="true" />
                                        <a class="p-icon-filter p-icon-filter-style" style="display: block; width: 22px;
                                        height: 22px; float: left">@Html.GetFilterItem("Order", typeof(int))</a>
                                    </td>
                                    <th>

                                    </th>
                                    <td></td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
</div>
@section foot
{
<script type="text/javascript">
    var jsonTree = @MvcHtmlString.Create(Model);
    var settings = { callback: { onClick: nodeClick } };
    var zTree = $.fn.zTree.init($("#tree"), settings, jsonTree);

    function nodeClick(e,treeId, treeNode)
    {
        $("#Parent\\.Id").val(treeNode.id);
        $("#grid-bundles").datagrid("load");
    }
    function dictionaryTypeAdd()
    {
        K.layer.iframe({
            title: "@Html.GetLayerTitle(LayerIcon.Add,"新增字典类别")",
            initfull: true,
            maxmin: true,
            btn: ["保存", "返回"],
            content: "@Url.Content("~/Sys/Dictionary/DictionaryTypeAdd")",
            area: ["480px", "340px"],
            callback: function (result) {
                if(K.ShowOrAlert(result)){
                    loadDictionaryTypeTree();
                    $("#grid-bundles").datagrid("load");
                }
            }
        });
    }
    function dictionaryTypeEdit()
    {
        var nodes = zTree.getSelectedNodes();
        if(nodes.length>0)
        {
            K.layer.iframe({
                title: "@Html.GetLayerTitle(LayerIcon.Edit,"编辑字典类别")",
                initfull: true,
                maxmin: true,
                btn: ["保存", "返回"],
                content: "@Url.Content("~/Sys/Dictionary/DictionaryTypeEdit")?CatalogId=" + nodes[0].id,
                area: ["480px", "340px"],
                callback: function (result) {
                    if (K.ShowOrAlert(result)) {
                        loadDictionaryTypeTree();
                    }
                }
            });
        }
        else
        {
            KingsSharp.Alert("请选择需要编辑的目录节点，根目录无法编辑");
        }
    }

    function dictionaryImport()
    {
        var layerOptions={
            url:"@Url.Content("~/Sys/Dictionary/DictionaryImport")",
            title:"<span class=\"p-icon-add icon\">批量导入数据字典</span>",
            width: 540, height: 460,
            layerclass: KingsSharp.Animation("in",0,5),
            success: function (result,dto) {
                if(KingsSharp.ShowOrAlert(result)){
                    $("#grid-bundles").datagrid("load");
                }
            }
        };
        var dictionaryTypeLayer= KingsSharp.Layer(layerOptions);
    }

    function dictionaryAdd()
    {
        K.layer.iframe({
            title: "@Html.GetLayerTitle(LayerIcon.Add,"新增字典")",
            initfull: true,
            maxmin: true,
            btn: ["保存", "返回"],
            content: "@Url.Content("~/Sys/Dictionary/DictionaryAdd")",
            area: ["480px", "440px"],
            callback: function (result,dto) {
                if (K.ShowOrAlert(result)) {
                    var dtoobject=JSON.parse(dto);
                    $("#Parent\\.Id").val(dtoobject.Pid);
                    var treeObj= $.fn.zTree.getZTreeObj("tree");
                    var node = treeObj.getNodeByParam("id", dtoobject.Pid);
                    treeObj.selectNode(node);
                    $("#grid-bundles").datagrid("load");
                }
            }
        });
    }

    function dictionaryEdit(id)
    {
        K.layer.iframe({
            title: "@Html.GetLayerTitle(LayerIcon.Edit,"编辑字典")",
            initfull: true,
            maxmin: true,
            btn: ["保存", "返回"],
            content: "@Url.Content("~/Sys/Dictionary/DictionaryEdit")?Id=" + id,
            area: ["480px", "445px"],
            callback: function (result,dto) {
                if (K.ShowOrAlert(result)) {
                    var dtoobject=JSON.parse(dto);
                    $("#Parent\\.Id").val(dtoobject.Pid);
                    var treeObj= $.fn.zTree.getZTreeObj("tree");
                    var node = treeObj.getNodeByParam("id", dtoobject.Pid);
                    treeObj.selectNode(node);
                    $("#grid-bundles").datagrid("load");
                }
            }
         });
    }

    function rowEdit()
    {
        var row = $("#grid-bundles").datagrid('getSelected');
        if (row != null)
        {
            dictionaryEdit(row.Id);
        }
        else
        {
            KingsSharp.Alert("请选中需要编辑的行");
        }
    }
    function dictionaryDelete(rows)
    {
        var ids=[];
        for(var i=0;i<rows.length;i++)
        {
            ids.push(rows[i].Id);
        }
        KingsSharp.Confirm("确认删除字典["+rows[0].Name+"]...等"+rows.length+"条数据？",function(){
            KingsSharp.AjaxJson("@Url.Content("~/Sys/Dictionary/DeleteDictionary")",{deleteids:ids.join(",")},function(result){
                if(KingsSharp.ShowOrAlert(result)){
                    $("#grid-bundles").datagrid("load");
                }
            });
        })
    }
    function rowDelete()
    {
        var rows = $("#grid-bundles").datagrid('getChecked');
        if (rows != null && rows.length>0)
        {
            dictionaryDelete(rows);
        }
        else
        {
            KingsSharp.Alert("请选中需要删除的行");
        }
    }

    function loadDictionaryTypeTree()
    {
        KingsSharp.AjaxJson("@Url.Content("~/Sys/Dictionary/GetDictionaryTypeTree")",null,function(treedata){
            if(typeof(treedata)=="string")
            {
                jsonTree=JSON.parse(treedata);
            }
            else
            {
                jsonTree=treedata;
            }
            zTree = $.fn.zTree.init($("#tree"), settings, jsonTree);
        });
    }

    function LoadGridData()
    {
        var columns = [[
            { field: "ck", checkbox: true},
            { field: "Name", title: "字典名称", width: 180, sortable: true,formatter:function(val,row,index){
                return "<a onclick=\"dictionaryEdit('" + row.Id + "')\">" + val + "</a>";
            }},
            { field: "Description", title: "字典说明", width: 400},
            { field: "DictionaryTypeName", title: "字典类别"},
            { field: "Order", title: "排序", width: 40, sortable: true, halign: "center", align: "center" }
        ]];
        var parameter = {
            title: "@Html.GetGridTitle("系统管理","数据字典")",
            columns: columns,
            url: "@Url.Content("~/Sys/Dictionary/GetDictionaryGridData")",
            pageNumber: 1,
            DblClickRow: rowEdit
        };
        var grid= KingsSharp.GetGridData("#grid-bundles",parameter).Grid;
    }
    LoadGridData();
      </script>
}


